package com.gome.transactiontree.sample.case2;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.gome.transactiontree.api.TransactionNode;

@Service
public class BusinessA {

	private static final Logger LOG = LoggerFactory.getLogger(BusinessA.class);
	
	@Resource(name="remote1")
	private Remote1 remote1;
	
	@Resource(name="remote2")
	private Remote2 remote2;
	
	@TransactionNode(commit = "a1_confirm", rollback = "a1_cannel")
	public String a1(String txid, String p2) {
		LOG.info("TCC BusinessA.a1({},{})", txid, p2);
		
		remote1.r1(txid, p2);
		
		remote2.r2(txid, p2);
		
		return txid;
	}

	public void a1_confirm(String txid, String p2) {
		LOG.info("TCC BusinessA.a1_confirm({},{})", txid, p2);
	}
	
	public void a1_cannel(String txid, String p2) {
		LOG.info("TCC BusinessA.a1_cannel({},{})", txid, p2);
	}
}